//
//  OpenCoverViewController.m
//  OpenCover
//
//  Created by bh.0422 on 11-6-16.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "OpenCoverViewController.h"
#import "UIImage-Extensions.h"

@implementation OpenCoverViewController

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	
	openFlow=[[AFOpenFlowView alloc] initWithFrame:self.view.bounds];
	
	[openFlow setBackgroundColor:[UIColor blackColor]];
	[openFlow setDataSource:self];
	[openFlow setViewDelegate:self];
	
	m_ShowImgArr= [[NSMutableArray alloc] init];
	for (int i = 0; i<11; i++) {
		UIImage *image =[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]];
		image = [image imageByScalingToSize:CGSizeMake(360, 480)];
		[m_ShowImgArr addObject:image];
	}

	//设置图片轮寻的数量
	int count = [m_ShowImgArr count];
	[openFlow setNumberOfImages:count];
	for (int i=0; i<count; i++) {
		UIImage *image = [m_ShowImgArr objectAtIndex:i];
		[openFlow setImage:image forIndex:i];
	}	
	[self.view addSubview:openFlow];
	[openFlow release];
	
}

#pragma mark datasouce

- (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index{
	NSLog(@"request image for index called %d",index);
}

- (void)openFlowView:(AFOpenFlowView *)openFlowView selectionDidChange:(int)index{
	NSLog(@"selection did change called %d",index);
}
- (void)openFlowView:(AFOpenFlowView *)openFlowView singleTaped:(int)index
{
	NSLog(@"singleTaped %d",index);
	
	NSLog(@"%@",[openFlowView superview]);
	
}

- (UIImage *)defaultImage{
	NSLog(@"default call");
	return [UIImage imageNamed:@"default.jpg"];
}



- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
								duration:(NSTimeInterval)duration
{
	[UIView beginAnimations:nil context:nil];
	if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
		if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
		{
			// this is ipad 
			NSLog(@"this is ipad");
			[openFlow setFrame:CGRectMake(0, 0, 768, 1024)];
			
		}else 
		{
			// this is iphone 
			NSLog(@"this is iphone");
			[openFlow setFrame:CGRectMake(0, 0, 320, 480)];
		}	
	}else {
		if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
		{
			// this is ipad 
			NSLog(@"this is ipad");
			[openFlow setFrame:CGRectMake(0, 0, 1024, 748)];
			
		}else 
		{
			// this is iphone 
			NSLog(@"this is iphone");
			[openFlow setFrame:CGRectMake(0, 0, 480, 320)];
		}
	}
	[UIView commitAnimations];
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
